package com.reform.controller.project;

import com.reform.pojo.project.Project;
import com.reform.res.Result;
import com.reform.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

/**
 * <p>
 * 项目基本信息 前端控制器
 * </p>
 *
 * @author mortale
 * @since 2021-07-20
 */
@Api(tags = "ProjectInfoController")
@RestController
@RequestMapping("/projectInfo")
public class ProjectInfoController {

    @Autowired
    IProjectService projectService;
    @Autowired
    IProjectMemberService projectMemberService;
    @Autowired
    IProjectSearchingService projectSearchingService;
    @Autowired
    IProjectTeachingService projectTeachingService;
    @Autowired
    IViewProjectService viewProjectService;

    @ApiOperation(value = "创建项目", notes = "创建项目")
    @PostMapping("/creatProjects")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectMembers", value = "项目成员列表" +
                    "[{ \"memberName\": \"\",\"memberAge\": \"\", \"memberSex\": \"\",\"memberTitle\":" +
                    " \"\",\"memberJob\": \"\",\"memberDep\": \"\",\"memberResearchareas\": \"\"," +
                    "\"memberDivision\": \"\",\"memberSignature\": \"\",\"ranking\": ,\"belong\":" +
                    "\"\",\"idcard\": \"\"},{...}]", paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "projectSearchings", value = "主要科学研究和教学研究工作简历列表" +
                    "[{\"searchingDate\": \"\",\"searchingName\": \"\",\"searchingSource\": \"\",\"searchingSearchstatus" +
                    "\": \"\",\"searchingAwards\": \"\",\"searchingMaterials\": \"\",\"handwriting\":\"\"},{...}]",
                    paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "projectTeachings", value = "主要教学工作简历列表" +
                    "[{\"teachingDate\": \"\",\"teachingCoursename\": \"\",\"teachingPrelectobject\":" +
                    "\"\",\"teachingLearnhour\": \"\",\"teachingDepartment\": \"\"},{...}]",
                    paramType = "query", dataTypeClass = String.class),
    })
    public Result creatProjects(Project project, String projectMembers, String projectSearchings, String projectTeachings) throws SQLException {
        return viewProjectService.creatProjects(project, projectMembers, projectSearchings, projectTeachings);
    }

    @ApiOperation(value = "删除项目", notes = "删除项目")
    @PostMapping("/deleteProject")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "proId", value = "项目id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result deleteProject(String proId) throws SQLException {
        return viewProjectService.deleteProject(proId);
    }

    @ApiOperation(value = "删除主要科学研究和教学研究工作简历", notes = "删除主要科学研究和教学研究工作简历")
    @PostMapping("/deleteProjectSearchingBySearchingId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "searching_id", value = "研究工作简历编号", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result deleteProjectSearchingBySearchingId(String searching_id) throws SQLException {
        viewProjectService.updateRides();
        return projectSearchingService.deleteProjectSearchingBySearchingId(searching_id);
    }

    @ApiOperation(value = "删除主要教学工作简历", notes = "删除主要教学工作简历")
    @PostMapping("/deleteProjectTeaching")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teaching_id", value = "主要教学工作简历id", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result deleteProjectTeachingByTeachingId(String teaching_id) throws SQLException {
        return projectTeachingService.deleteProjectTeachingByTeachingId(teaching_id);
    }

    @ApiOperation(value = "删除项目成员", notes = "删除项目成员")
    @PostMapping("/deleteProjectMember")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "member_id", value = "项目成员id", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result deleteProjectMemberByMemberId(String member_id) throws SQLException {
        return projectMemberService.deleteProjectMemberByMemberId(member_id);
    }

    @ApiOperation(value = "修改项目", notes = "修改项目")
    @PostMapping("/updateProject")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectMembers", value = "项目成员列表", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "projectSearchings", value = "主要科学研究和教学研究工作简历列表", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "projectTeachings", value = "主要教学工作简历列表", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result updateProject(Project project, String projectMembers, String projectSearchings, String projectTeachings) throws SQLException {
        return viewProjectService.updateProject(project, projectMembers, projectSearchings, projectTeachings);
    }

    @ApiOperation(value = "添加项目成员", notes = "添加项目成员")
    @PostMapping("/insertProjectMember")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectMembers", value = "项目成员列表,需要项目编号(project.pro_id)", paramType = "query", dataTypeClass = String.class, required = true)
    })
    public Result insertProjectMember(String projectMembers) throws SQLException {
        return projectMemberService.insertProjectMember(projectMembers);
    }

    @ApiOperation(value = "添加主要教学工作简历", notes = "添加主要教学工作简历")
    @PostMapping("/insertProjectTeaching")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectTeachings", value = "主要教学工作简历列表,需要项目编号(project.pro_id)", paramType = "query", dataTypeClass = String.class, required = true)
    })
    public Result insertProjectTeaching(String projectTeachings) throws SQLException {
        return projectTeachingService.insertProjectTeaching(projectTeachings);
    }

    @ApiOperation(value = "添加主要科学研究和教学研究工作简历", notes = "添加主要科学研究和教学研究工作简历")
    @PostMapping("/insertProjectSearching")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectSearchings", value = "主要科学研究和教学研究工作简历列表,需要项目编号(project.pro_id)", paramType = "query", dataTypeClass = String.class, required = true)
    })
    public Result insertProjectSearching(String projectSearchings) throws SQLException {
        return projectSearchingService.insertProjectSearching(projectSearchings);
    }

    @ApiOperation(value = "项目名查重", notes = "项目名重复率")
    @PostMapping("/nameRate")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batchId", value = "批次id", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "proId", value = "项目id", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "projectName", value = "项目名", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "repetitionRate", value = "重复率,默认0.6", paramType = "query", dataTypeClass = Float.class, required = false)
    })
    public Result nameRate(String batchId, String proId, String projectName, Float repetitionRate) throws SQLException {
        return projectService.nameRate(batchId, proId, projectName, repetitionRate);
    }

    @ApiOperation(value = "根据gh获取该教师主持的项目信息", notes = "根据gh获取该教师主持的项目信息")
    @PostMapping("/getProjectsByGH")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gh", value = "教师工号", paramType = "query", dataTypeClass = String.class, required = true)
    })
    public Result getProjectsByGH(String gh) throws SQLException {
        return projectService.getProjectsByGH(gh);
    }

    @ApiOperation(value = "获取该教师主持的简单项目信息", notes = "根据gh获取该教师主持的简单项目信息")
    @GetMapping("/getHostProjects")
    public Result getHostProjects(HttpServletRequest request) throws SQLException {
        return projectService.getHostProjectsByGH(request);
    }

    @ApiOperation(value = "获取该教师参与的简单项目信息", notes = "根据gh获取该教师参与的简单项目信息")
    @GetMapping("/getPartakeProjects")
    public Result getPartakeProjects(HttpServletRequest request) throws SQLException {
        return projectService.getPartakeProjectsByGH(request);
    }

    @ApiOperation(value = "通过项目id修改项目状态", notes = "通过项目id修改项目状态")
    @PostMapping("/updateProByProId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "proId", value = "项目id", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "proApproval", value = "项目状态", paramType = "query", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "proStatus", value = "项目状态", paramType = "query", dataTypeClass = Integer.class, required = true)
    })
    public Result updateProByProId(String proId, Integer proApproval, Integer proStatus) throws SQLException {
        return projectService.updateProByProId(proId, proApproval,proStatus);
    }

    @ApiOperation(value = "通过项目id批量修改项目状态", notes = "通过项目id批量修改项目状态")
    @PostMapping("/updateProsByProId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectStatus", value = "proId，proApproval，proStatus。项目信息", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result updateProsByProId(String projectStatus) throws SQLException {
        return projectService.updateProsByProId(projectStatus);
    }

    @ApiOperation(value = "通过项目id修改项目阶段信息是否暂存", notes = "通过项目id修改项目阶段信息是否暂存")
    @PostMapping("/updateProStatusByProId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "proId", value = "项目id", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "proStatus", value = "项目状态", paramType = "query", dataTypeClass = Integer.class, required = true)
    })
    public Result updateProStatusByProId(String proId, Integer proStatus) throws SQLException {
        return projectService.updateProStatusByProId(proId, proStatus);
    }

    @ApiOperation(value = "通过项目id添加项目延期原因", notes = "通过项目id添加项目延期原因")
    @PostMapping("/addDelayCauseByProId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "proId", value = "项目id", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "delayCause", value = "延期原因", paramType = "query", dataTypeClass = String.class, required = true)
    })
    public Result addDelayCauseByProId(String proId, String delayCause) throws SQLException {
        return projectService.addDelayCauseByProId(proId, delayCause);
    }

    @ApiOperation(value = "通过项目id查看项目延期原因", notes = "通过项目id查看项目延期原因")
    @PostMapping("/getDelayCauseByProId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "proId", value = "项目id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getDelayCauseByProId(String proId) throws SQLException {
        return projectService.getDelayCauseByProId(proId);
    }
}
